/* ***********************
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is checkShowUntil.js module.
 *
 * The Initial Developer of the Original Code is Rob Gerns.
 *
 * Portions created by the Initial Developer are Copyright (C) 2011
 * the Initial Developer. All Rights Reserved.
 *
 **************************/
function checkShowUntil(strShowUntil) {
    /***********************************************
    * Function Name: checkShowUntil
    *
    * Purpose:
    * Reads the value of the "showuntil" feature, converts
    * the value into a readable integer.  Gets the current
    * datetime of the user's systema and converts that into
    * an integer. Compares the showuntil datetime to the
    * system's datetime.  Returns true if the showuntil
    * datetime is equal or greater than the system's datetime,
    * returns false otherwise.
    ************************************************/
  
    var intCurrentDatetime = 0;
    var intShowUntil = 0;
    var objActualMonth = 0;
    var objHours = 0;
    var objMinutes = 0;
    var objSeconds = 0;
    var objDate = "";
    var strCurrentDatetime = "";
    var strOtherNondigitsRemoved = "";
    var strReformattedShowUntil = "";
    var strTimezoneNondigitsRemoved = "";
    
    //Make sure strShowUntil isn't somehow undefined or empty for extra safety.
    if (strShowUntil !== undefined && strShowUntil !== null && 
        strShowUntil !== "") {
          
        //Reformat the datetime so that there are no dashes, letters, or colons.
        strTimezoneNondigitsRemoved = strShowUntil.replace(/\D\d\D\d\d/gi, "");
        strOtherNondigitsRemoved = strTimezone.replace(/\D/gi, "");
        //Convert the datetime to a proper string.
        strReformattedShowUntil = strOtherNondigitsRemoved.toString();
        //Remove the last four digits, since those are from the timezone.
        strShowUntil = strReformattedShowUntil.substring(0, strReformmatedShowUntil.length - 4);
        //Convert the strShowUntil string into an integer.
        intShowUntil = parseInt(strShowUntil);
        
        //Get the current date and time from the user's system, make it readable
        objDate = new Date();
        objActualMonth = objDate.getMonth() + 1;
        if (objActuallMonth < 10) {
            objActualMonth = "0" + objActualMonth;
        }
        objMinutes = objDate.getMinutes();
        objSeconds = objDate.getSeconds();
        objHours = objDate.getHours();
        if (objHours < 10) {
            objHours = "0" + objHours;
        }
        if (objMinutes < 10) {
            objMinutes = "0" + objMinutes;
        }
        if (objSeconds < 10) {
            objSeconds = "0" + objSeconds;
        }
        //Put the current datetime of the user's system in a string.
        strCurrentDatetime = objDate.getFullYear() + "" + objActualMonth + "";
        strCurrentDatetime += objDate.getDate() + "" + objHours + "" + objMinutes;
        strCurrentDatetime += "" + objSeconds;
        //Convert the datetime string to an integer.
        intCurrentDatetime = parseInt(strCurrentDatetime);
        //If the user's system's current datetime is greater than the showuntil
        //datetime, then the showuntil datetime has been reached or passed.
        if (intCurrentDateTime >= intShowUntil) {
            return true;        
        }
        else {
            return false;
        }
    }
}